package com.zht.handle;

import com.zht.dao.UserDao;
import com.zht.view.LoginView;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LoginHandler  implements ActionListener {
    /* 把JFrame*/
    LoginView loginView  = null;

    public LoginHandler(LoginView loginView){
        this.loginView = loginView;
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        /* 考虑点击了之后，要处理的业务
        * 1. 获取用户在输入框输入的值。
        * 2. 要连接数据，去进行比对
        * 3.有 进入 另一个
        *   没有，提示错误
        * */
        System.out.println("按钮被点击了");
        /**/
        JTextField nameField = loginView.getNameField();
        String user = nameField.getText();

        JPasswordField pwdField = loginView.getPwdField();
        String pwd = pwdField.getText();
        System.out.println(user);
        System.out.println(pwd);
        UserDao userDao = new UserDao();
        boolean success = userDao.login(user, pwd);
        if(success){
            System.out.println("登陆成功");
        }else {
            System.out.println("登陆失败");
        }
    }
}
